package com.mxpio.erp.common.oa.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.mxpio.erp.common.jpa.policy.ResCodeGeneratorPolicy;
import com.mxpioframework.filestorage.entity.MxpioFileInfo;
import com.mxpioframework.jpa.annotation.Generator;
import com.mxpioframework.security.annotation.Dict;
import com.mxpioframework.security.entity.BaseEntity;
import com.mxpioframework.security.entity.Dept;
import com.mxpioframework.security.entity.User;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

@Data
@EqualsAndHashCode(callSuper=false)
@Entity
@Table(name = "MB_ERP_OA_BUSINESS_TRIP_APPLY")
@Schema(description="出差申请单")
public class OaBusinessTripApply extends BaseEntity  {


    @Id
    @Column(name = "BIZ_NO_", updatable = false)
    @Generator(policy = ResCodeGeneratorPolicy.class)
    @Schema(description = "工单编号")
    private String bizNo;

    @Column(name = "APPLICANT_")
    @Schema(description = "申请人")
    @Dict(dicCode = "username", dicEntity = User.class, dicText = "nickname")
    private String applicant;

    @Column(name = "DEPT_CODE_")
    @Schema(description = "申请部门编号")
    @Dict(dicCode="deptCode", dicEntity = Dept.class, dicText = "deptName")
    private String deptCode;

    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @Schema(description = "申请时间")
    @Column(name = "APPLY_TIME_")
    private Date applyTime;

    @Column(name = "BUSTRIP_ADDRESS_")
    @Schema(description = "出差地点")
    private String busTripAddress;

    /*@Column(name = "BUSTRIP_FEE_")
    @Schema(description = "暂支差旅费")
    private String busTripFee;*/

    @Column(name = "BUSTRIP_REASON_",columnDefinition = "TEXT")
    @Schema(description = "出差事由")
    private String busTripReason;

    /*@Column(name = "EXCEPT_BUSTRIP_ROUTE_")
    @Schema(description = "预计交通路线")
    private String expectBusTripRoute;

    @Column(name = "REAL_BUSTRIP_ROUTE_")
    @Schema(description = "实际交通路线")
    private String realBusTripRoute;*/

    /*@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @Column(name = "EXPECT_BUSTRIP_START_TIME_")
    @Schema(description = "预计出差开始时间")
    private Date expectBusTripStartTime;

    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @Column(name = "EXPECT_BUSTRIP_END_TIME_")
    @Schema(description = "预计出差结束时间")
    private Date expectBusTripEndTime;

    @Column(name = "EXPECT_BUSTRIP_DAYS_")
    @Schema(description = "预计出差天数")
    private Integer expectBusTripDays;*/

    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern="yyyy-MM-dd")
    @Column(name = "REAL_BUSTRIP_START_TIME_")
    @Schema(description = "实际出差开始时间")
    private Date realBusTripStartTime;

    @Column(name = "S_AM_PM_VALUE_",columnDefinition = "TINYINT(1)")
    @Schema(description = "开始时间上午/下午 AM 存为 0，PM 存为 1")
    private int sAmPmValue;

    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern="yyyy-MM-dd")
    @Column(name = "REAL_BUSTRIP_END_TIME_")
    @Schema(description = "实际出差结束时间")
    private Date realBusTripEndTime;

    @Column(name = "E_AM_PM_VALUE_" ,columnDefinition = "TINYINT(1)")
    @Schema(description = "结束时间上午/下午 AM 存为 0，PM 存为 1")
    private int eAmPmValue;

    @Column(name = "REAL_BUSTRIP_DAYS_")
    @Schema(description = "实际出差天数")
    private Integer realBusTripDays;

    /*@Column(name = "ORDER_STATUS_")
    @Schema(description = "工单状态") //10新增 20审核中 30已完成 40已关闭
    @Dict(dicCode = "MB_ERP_OA_INVOICE_ORDER_STATUS")
    private String orderStatus;*/

    @Column(name = "ATTR_URL_")
    @Schema(description = "附件")
    @Dict(dicCode = "fileNo", dicEntity = MxpioFileInfo.class, dicText = "fileName")
    private String attrUrl;

    /**审批状态*/
    @Column(name = "BPMN_STATUS_")
    @Schema(description = "审批状态")
    @Dict(dicCode = "ERP_COMMON_BPMN_STATUS")
    private String bpmnStatus;

    /**审批实例ID*/
    @Column(name = "PROCESS_INSTANCE_ID_")
    @Schema(description = "审批实例ID")
    private String processInstanceId;

    @Column(name = "SOURCE_BIZ_NO_")
    @Schema(description = "源工单编号(变更单源单)")
    private String sourceBizNo;

    @Transient
    private List<OaBusinessTripApplyLine> lineList;

}
